package com.tywj.lib.core.common.util

import android.view.Gravity
import android.widget.TextView
import androidx.annotation.StringRes
import com.blankj.utilcode.util.ToastUtils
import com.tywj.lib.core.common.R

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : toast工具类
 *              统一toast样式
 *              解决小米手机toast会显示应用名称的问题
 *     version: 1.0.0
 * </pre>
 */
object ToastUtil {

    init {
        ToastUtils.setGravity(Gravity.CENTER, 0, 0)
    }

    fun shortToast(msg: CharSequence) {
        val llToast = ToastUtils.showCustomShort(R.layout.lib_core_layout_toast)
        llToast.findViewById<TextView>(R.id.tvToast).text = msg
    }

    fun shortToast(@StringRes id: Int) {
        shortToast(
            ResourcesUtil.getString(
                id
            )
        )
    }

    fun longToast(msg: CharSequence) {
        val llToast = ToastUtils.showCustomLong(R.layout.lib_core_layout_toast)
        llToast.findViewById<TextView>(R.id.tvToast).text = msg
    }

    fun longToast(@StringRes id: Int) {
        longToast(
            ResourcesUtil.getString(
                id
            )
        )
    }
}